var list = null;
function btnSubmit(param){
    var serviceList=new Array();
    if(param == "save"){
        var formdata = $("#servicecong_frm_main").serializeObject();
        var pricevalue = null;
        var desc = null;
        var servicetitle=null;
        list.forEach(function (item,index) {
            pricevalue = $(":input[ name = 'price"+list[index].id+"' ]").val();
            desc = $("textarea[name^=desc"+list[index].id+" ]").val();
            console.log(desc)
            servicetitle = $(":input[ name = 'title"+list[index].id+"' ]").val();
            if(!server.isEmpty(pricevalue)){
                var newItem = {};
                newItem.serviceId = list[index].id;
                newItem.originalPrice=pricevalue;
                newItem.discountPrice=pricevalue;
                newItem.description=desc;
                newItem.serviceTitle=servicetitle;
                serviceList.push(newItem);

            }
        });
        server.req('wechat/teacherservice/updateServiceList',serviceList,function (res) {
            console.log(res);
            if(res.code==0){
                // console.log("success");
                pop_up("设置成功");
                server.loadindex('page/teacher/teacherindex/teacherindex');
            }
        },null,"POST")

    }else if(param == "cancel"){
        server.loadindex('page/teacher/teacherindex/teacherindex');
    }
};
$(function(){
    server.req('wechat/service/alllist',{},function (e) {
        // console.log(e);
        if(e.code==0){
            var data = e.data;
            list = data;
            server.loadData('.content-body',e);

            server.req('wechat/teacherservice/getByTeacherId',{},function (res) {
                // console.log('get service list by teacherId');
                // console.log(res);
                for(var i =0 ;i<res.data.length;i++){
                    res.data[i]["price"+res.data[i].serviceId]=res.data[i].discountPrice;
                    res.data[i]["title"+res.data[i].serviceId]=res.data[i].serviceTitle;
                    res.data[i]["desc"+res.data[i].serviceId]=res.data[i].description;
                    $("#price"+res.data[i].serviceId).val(res.data[i].discountPrice);
                    $("#title"+res.data[i].serviceId).val(res.data[i].serviceTitle);
                    $("#desc"+res.data[i].serviceId).val(res.data[i].description);
                    // server.loadData('.content-body-item-right',res.data[i]);
                    // server.loadData('.content-body-item2-right',res.data[i]);

                    // console.log(res.data[i]);
                }


            })
        }
    });

})